package com.rrd.itext.utils;

import java.io.ByteArrayOutputStream;
import java.io.InputStream;
import java.io.OutputStreamWriter;
import java.net.HttpURLConnection;
import java.net.URL;

import com.thoughtworks.xstream.core.util.FastStack;
import com.thoughtworks.xstream.io.HierarchicalStreamReader;

public class HttpClientUtil {
    private static HttpClientUtil self;
    private HttpClientUtil(){
        
    }
    public static HttpClientUtil getInstence(){
        if(self == null){
            self = new HttpClientUtil();
        }
        return self;
    }
    
    public byte[] requestURL(String target) throws Exception{
        if(target == null){
            return null;
        }
        URL url = new URL(target);  
        HttpURLConnection conn = (HttpURLConnection)url.openConnection();  
        conn.setRequestMethod("POST");
        conn.setDoOutput(true);
        InputStream in = conn.getInputStream();
        byte[] tmp = new byte[512];
        ByteArrayOutputStream out = new ByteArrayOutputStream();
        int bytesRead = in.read(tmp);
        while (bytesRead != -1) {
            out.write(tmp, 0, bytesRead);
            bytesRead = in.read(tmp);
        }
        return out.toByteArray();
    }
}
